package br.com.moxeon.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.moxeon.model.cash.ThrowOperation;
import br.com.moxeon.model.enums.AccountSituation;
import br.com.vexillum.model.annotations.Validate;

@SuppressWarnings("serial")
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="type")
@Table(name="accounts")
public abstract class Accounts extends MoxeonControlledPersistentEntity{
	/*
	@OneToMany(targetEntity=Lancamento.class,fetch=FetchType.LAZY,mappedBy="contasFinanceiro")
	Lancamento lancamento;
	*/
	@Column(nullable=true, name="pay_date")
	private Date payDate;
	
	@ManyToOne(targetEntity=ThrowOperation.class,fetch=FetchType.LAZY)
	@Cascade(value={CascadeType.SAVE_UPDATE, CascadeType.MERGE})
	private ThrowOperation operation;

	@Column(nullable=false, name="monthReference")
	@Validate(notNull=true)
	private Date monthReference;
	
	@Validate(notNull=true)
	@Column(nullable=false, name="value")
	private Double value;
	
	
	@Validate(notNull=true)
	@Column(nullable=false, name="issueDate")
	private Date issueDate;
	
	@Column(name="accountSituation", unique=false, updatable=true)
	@Enumerated(EnumType.ORDINAL)
	private AccountSituation accountSituation;
	
	@Transient
	private Double valueTotalPortion;
	
	public ThrowOperation getOperation() {
		return operation;
	}

	public void setOperation(ThrowOperation operation) {
		this.operation = operation;
	}

	public Date getMonthReference() {
		return monthReference;
	}

	public void setMonthReference(Date monthReference) {
		this.monthReference = monthReference;
	}

	public Double getValue() {
		return value;
	}

	public void setValue(Double value) {
		this.value = value;
	}

	public Date getIssueDate() {
		return issueDate;
	}

	public void setIssueDate(Date issueDate) {
		this.issueDate = issueDate;
	}

	public Double getValueTotalPortion() {
		return valueTotalPortion;
	}

	public void setValueTotalPortion(Double valueTotalPortion) {
		this.valueTotalPortion = valueTotalPortion;
	}

	public AccountSituation getAccountSituation() {
		return accountSituation;
	}

	public void setAccountSituation(AccountSituation accountSituation) {
		this.accountSituation = accountSituation;
	}
	
	public abstract Double getValueInDownload();
	public abstract void setValueInDownload(Double value);

	public Date getPayDate() {
		return payDate;
	}

	public void setPayDate(Date payDate) {
		this.payDate = payDate;
	}
}